package com.lyp.qczp.contoller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import com.lyp.qczp.dao.Leixingdao;
import com.lyp.qczp.entity.Kaoti;
import com.lyp.qczp.entity.Leixing;
import com.lyp.qczp.service.KaotiService;
@RestController
@CrossOrigin(origins = "*")
public class KaotiController {
	@Autowired
	private KaotiService kaotiService;
	@Autowired
	private Leixingdao leixingdao;
	
	@PostMapping("/findBylFather")
	public List<Leixing> findBylFather(Integer lFather) {
		// TODO Auto-generated method stub
		
		return leixingdao.findBylFather(lFather);
	}
	@PostMapping("/findLeixing")
	public List<Leixing> findLeixing() {
		// TODO Auto-generated method stub
		
		return leixingdao.findAll();
	}
	
	@PostMapping("/saveKaoti")
	public int saveRoles(Kaoti kaoti) {
		return kaotiService.save(kaoti);
	}
	@PostMapping("/deleteKaoti")
	public int deleteById(Integer kId) {
		// TODO Auto-generated method stub
		
		return kaotiService.deleteById(kId);
	}
	@PostMapping("/findAllKaoti")
	public Map<String, Object> findAll(Integer page,Integer rows,Kaoti kaoti) {
		PageRequest of = PageRequest.of(page-1, rows);
		return kaotiService.findAll(of,kaoti);
	}
	@PostMapping("/findBykEr")
	public List<Kaoti> findBykEr(Integer kEr) {
		return kaotiService.findBykEr(kEr);
	}
	
	@PostMapping("/findBykErcount")
	public Integer findBykErcount(Integer kEr) {
		return kaotiService.findBykEr(kEr).size();
	}
}
